package cn.yeamin.spring.boot.service;

import cn.yeamin.spring.boot.one.mapper.OneGirlMapper;
import cn.yeamin.spring.boot.pojo.Girl;
import cn.yeamin.spring.boot.two.mapper.TwoGirlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @classDesc: 功能描述:()
 * @author: 李彤
 * @createTime: 2017年6月29日 下午12:11:26
 * @version: v1.0
 * @copyright:奕明(上海)影视传媒有限公司
 */
@Service
 // 如果Service层try-Catch了,这个注解不能够回滚事务,需要在Catch中手动回滚事务
public class GirlService {

	@Autowired
	private OneGirlMapper oneMapper;

	@Autowired
	private TwoGirlMapper twoMapper;

	public void add() {
		//try {
		Girl girl1 = new Girl("高圆圆",29,"北京东城");
		oneMapper.add(girl1);
		//int i = 1 / 0; // 模拟异常
		Girl girl2 = new Girl("唐嫣",26,"上海浦东");
		twoMapper.add(girl2);
		 /*} catch (Exception e) {
			//手动回滚事务
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		    e.printStackTrace();
		}*/
	}
}
